package com.infore.airsupervise.ui.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.infore.airsupervise.R;
import com.infore.airsupervise.http.BaseResponse;

import java.util.ArrayList;
import java.util.List;

import butterknife.Unbinder;
import retrofit2.Call;

/**
 * Fragment 基类
 */
public class BaseFragment extends Fragment {

    protected Unbinder unbinder;
    protected List<Call<BaseResponse>> requests = new ArrayList<>();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    public void onStop() {
        super.onStop();

        // 停止所有网络请求
        for (Call<BaseResponse> call : requests) {
            if (!call.isCanceled()) {
                call.cancel();
            }
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if (unbinder != null) {
            unbinder.unbind();
        }
    }

}
